/////////////////////////////////////////////////
//// ASKIMA - RTU AREA
//// NOTIFICATION SYSTEM MANAGEMENT FUNCTIONS
/////////////////////////////////////////////////

/**
 * Open a windows for notifications
 */

function openNotificationWindow(collaboratorLogin, collaboratorID) {
	$("#notificationForm")
			.html(
					"<span>Collaborateur destinataire : "
							+ collaboratorLogin
							+ "</span><br/><textarea id='notificationMessage'></textarea><button id='sendNotificationButton' onclick='javascript:sendNotification("
							+ collaboratorID
							+ ")'>Envoyer Notification</button>");
	$("#notificationForm").dialog({
		title : 'Envoyer une notification',
		width : 400,
		close : function(event, ui) {
			cleanNotificationForm();
		}
	});
}

/**
 * Send a notification to a collaborator
 * 
 * @param collaboratorID
 */

function sendNotification(collaboratorID) {

	var message = $('#notificationForm > #notificationMessage').val();

	$.getJSON("sendNotificationToCollaborator", {
		collaboratorID : collaboratorID,
		message : message
	}, function(data) {
		if (data == true) {
			alert("La notification a été postée.");
		} else {
			alert("Une erreur est survenue");
		}
		$("#notificationForm").dialog('close');
	});
}

/**
 * Clean the notification form (delete content)
 */

function cleanNotificationForm() {
	$("#notificationForm").html("");
}